from Function import *

class Rosenbrock(Function):
    def f(self,vec):
        return 100*(vec[1,0]-vec[0,0]**2)**2+(1-vec[0,0])**2

class Beale(Function):
    def f(self,vec):
        return (1.5-vec[0,0]+vec[1,0]*vec[0,0])**2+(2.25-vec[0,0]+vec[0,0]*vec[1,0]**2)**2+(2.625-vec[0,0]+vec[0,0]*vec[1,0]**3)**2

F1 = Rosenbrock()
F2 = Beale()
x0 = np.array([[-1.2],[1.0]])
x1 = np.array([[1.0],[0]])

print(Hessian(F2,x0))
print(grad(F2,x0))
print("Rosenbrock function:")
ans = Steepest_Descent(F1,x0)
print("Ans:")
print(ans)
print("with error:",norm(grad(F1,ans)))
ans = Newton_Method(F1,x0)
print("Ans:")
print(ans)
print("with error:",norm(grad(F1,ans)))
print("Beale function:")
ans = Steepest_Descent(F2,x1)
print("Ans:")
print(ans)
print("with error:",norm(grad(F2,ans)))
ans = Newton_Method(F2,x1)
print("Ans:")
print(ans)
print("with error:",norm(grad(F2,ans)))